import React from 'react';
import {Select} from 'antd';
import {withRouter} from 'react-router-dom'
import { injectIntl } from 'react-intl';

const Option = Select.Option;


@withRouter
class MonthSelect  extends React.Component {
    constructor(props) {		
        super(props);        
        this.state={
        }
        this.getMonthList = this.getMonthList.bind(this);
        this.getMonth = this.getMonth.bind(this);
        this.getChargeMonth = this.getChargeMonth.bind(this);
    }

    componentWillMount(){
       let list = this.getMonthList();
       let value = this.getMonth();
       console.log(value)
       this.setState({
           content:[
                ...list
           ],
           defaultMonth:[
                value
           ]
       })
    }

    getMonth(){
        let myDate  = new Date();
        let month = myDate.getMonth() + 1;
        return  month;
    }

    //获取12个月的数字
    getMonthList=()=>{
        let MonthArr = new Array();
        for(let i=1;i<=12;i++){
            let jsonObj = {};
            jsonObj['value']=i;
            jsonObj['name']=i+this.props.intl.messages.common.months;
            MonthArr.push(jsonObj);
        }
        return MonthArr;
    }

    getChargeMonth=(value)=>{
        this.setState({
            defaultMonth:value
        })
        this.props.changeMonth(value);
    }


    render(){
        return(
                <Select value={this.state.defaultMonth} style={{ width: 120,marginRight:'20px' }}  onChange={this.getChargeMonth}>
                    {
                        this.state.content.map((child) => {
                            return (<Option key={child.value} value={child.value}>{child.name}</Option>)
                        })
                    }
                </Select>
        )
    }
}    
export default injectIntl(MonthSelect);